/*********************************************************************
 * URLDemo.java created on Feb 5, 2010
 *
 * This file is part of Sure Tech Support Portal System. 
 * Copyright @ 2010 Sure Tech (HK) Limited. All rights reserved.
 * Sure Tech PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *********************************************************************/
package test.com.bizdigger.util;

import java.awt.GridLayout;
import java.io.IOException;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import com.bizdigger.util.URLFactory;

/**
 * @Author: Mac Wang
 * @Date: Feb 5, 2010 2:24:19 PM 
 * @Email: mac@suretech.com.hk
 */

public class URLDemo extends JPanel{

	public static void main (final String[] args)
    {
        if (args.length == 0)
        {
            System.out.println ("usage: URLDemo url");
            System.exit (1);
        }
        final String iconURL = args [0];
        
        JFrame frame = new JFrame ("URL demo");
        
        frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
        URLDemo newContentPane = new URLDemo (iconURL);
        newContentPane.setOpaque (true);
        
        frame.setContentPane (newContentPane);
        frame.pack ();
        frame.setVisible (true);
    }
	
    public URLDemo (final String iconURL)
    {
        super (new GridLayout(1, 1));
        ImageIcon icon = createImageIcon (iconURL, "JavaWorld logo");
        JLabel label = new JLabel ("image loaded from " + iconURL, icon, JLabel.CENTER);
        add (label);
    }
    private static ImageIcon createImageIcon (final String url, final String description)
    {
        try
        {
            return new ImageIcon (URLFactory.newURL (url), description);
        }
        catch (IOException ioe)
        {
            System.err.println ("couldn't load icon URL: " + url);
            ioe.printStackTrace ();
            
            return null;
        }
    }
}
